﻿// +-------------------------------------------------------------------------
// | Copyright (C) 2016 Yunify, Inc.
// +-------------------------------------------------------------------------
// | Licensed under the Apache License, Version 2.0 (the "License");
// | you may not use this work except in compliance with the License.
// | You may obtain a copy of the License in the LICENSE file, or at:
// |
// | http://www.apache.org/licenses/LICENSE-2.0
// |
// | Unless required by applicable law or agreed to in writing, software
// | distributed under the License is distributed on an "AS IS" BASIS,
// | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// | See the License for the specific language governing permissions and
// | limitations under the License.
// +-------------------------------------------------------------------------

using System.Collections.Generic;
#if NETCOREAPP
using System.Net.Http;
#endif
using QingStor_SDK_NET.Common;
using QingStor_SDK_NET.Request;

// QingStorService: QingStor provides low-cost and reliable online storage service with unlimited storage space, high read and write performance, high reliability and data safety, fine-grained access control, and easy to use API.
namespace QingStor_SDK_NET.Service
{
    public class CListBucketsInput : ICustomType
	{
		public CListBucketsInput()
		{
		    this.Location = "";
		}

		// Limits results to buckets that in the location
	    [CParam(ParamType = "header", ParamName = "Location")]
	    public string Location { get; set; }
	}

	public class CListBucketsOutput : ICustomType
	{
		public int StatusCode { get; set; }
		public string RequestID { get; set; }
		public string ErrorCode { get; set; }

		// Buckets information
	    [CParam(ParamType = "query", ParamName = "buckets")]
	    public CBucketType[] buckets { get; set; }

		// Bucket count
	    [CParam(ParamType = "query", ParamName = "count")]
	    public long count { get; set; }
	}

	public class CQingStor
	{
		public CConfig Config { get; set; }
        public string Zone { get; set; }
#if NETCOREAPP
		public HttpClient HttpClient { get; set; }
#endif

		public CQingStor(CConfig Config)
		{
			this.Config = Config;
			this.Zone = "";
		}

		public CQingStor(CConfig Config, string Zone)
		{
			this.Config = Config;
			this.Zone = Zone;
		}

#if NETCOREAPP
		public CQingStor(CConfig Config, string Zone, HttpClient HttpClient)
        {
			this.Config = Config;
			this.Zone = Zone;
			this.HttpClient = HttpClient;
        }
#endif
		/*
         *
         * @param InputParam
         *
         * Documentation URL: https://docs.qingcloud.com/qingstor/api/service/get.html
        */
		public CListBucketsOutput ListBuckets(CListBucketsInput InputParam)
	    {
            Dictionary<object, object> dictInput = new Dictionary<object, object>();
		    if (dictInput == null)
		    {
			    return null;
		    }

		    string strURIPath = "/";
            dictInput.Add(ConstDef.REQ_HEADER_ZONE, this.Zone);
		    dictInput.Add(ConstDef.OPERATION_ID, "ListBuckets");
		    dictInput.Add(ConstDef.REQ_HEADER_METHOD, "GET");
		    dictInput.Add(ConstDef.REQ_HEADER_REQUEST_PATH, strURIPath);
		    dictInput.Add(ConstDef.REQ_HEADER_HOST, this.Config.Host);
		    dictInput.Add(ConstDef.REQ_HEADER_PORT, this.Config.Port);
		    dictInput.Add(ConstDef.REQ_HEADER_PROTOCOL, this.Config.Protocol);
		    dictInput.Add(ConstDef.REQ_HEADER_LOG_LEVEL, this.Config.LogLevel);
		    dictInput.Add(ConstDef.REQ_HEADER_CONNECT_RETRY, this.Config.ConnectionRetry);
		    dictInput.Add(ConstDef.REQ_HEADER_ACCESS_KEY_ID, this.Config.AccessKeyID);
		    dictInput.Add(ConstDef.REQ_HEADER_SECRET_ACCESS_KEY, this.Config.SecretAccessKey);

			CRequest request = CRequest.GetInstance();
#if NETCOREAPP
			request.ClientInstance = this.HttpClient;
#endif
			string strResponse = request.Request(dictInput, InputParam);
			return CJsonUtils.JsonToObject<CListBucketsOutput>(strResponse);		  
        }

        /*
         *
         * @param BucketName
         * @param Zone
         *
         * Get Bucket
        */
        public CBucket Bucket(string BucketName, string Zone)
        {
#if NETCOREAPP
			return new CBucket(this.Config, BucketName, Zone, this.HttpClient);
#else
			return new CBucket(this.Config, BucketName, Zone);
#endif
        }
	}
}﻿



















































